package com.example.springioc;

import com.example.springioc.controller.HelloController;
import com.example.springioc.model.UserInfo;
import lombok.val;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringIocApplication {

    public static void main(String[] args) {
        ApplicationContext context= (ApplicationContext) SpringApplication.run(SpringIocApplication.class, args);
        HelloController bean = context.getBean(HelloController.class);   //根据类型获取bean
        System.out.println(bean); //和下面两种方式拿到的对象是同一个
        bean.sayhi();

        HelloController helloController = (HelloController) context.getBean("helloController"); //名字--小驼峰命名
        System.out.println(helloController);
        helloController.sayhi();

        HelloController helloController1 = context.getBean("helloController", HelloController.class); //名字+类型
        System.out.println(helloController1);
        helloController1.sayhi();

        UserInfo bean1=context.getBean(UserInfo.class);
        System.out.println(bean1);

    }
    // bean类似于学生学号，他的名称在spring容器中是唯一的
    //默认情况下，首字母小写的驼峰表示  特殊情况下，如果类名前两位均为大写，那么bean的名称为类名本身

}
